import { ref, onMounted } from 'vue'
import { destinationApi } from '@/api/public/destination'
import type { Destination } from '@/types/destination'

export const useHome = () => {
  const destinations = ref<Destination[]>([])

  const fetchDestinations = async () => {
    try {
      const response = await destinationApi.getList()
      if (response.data.code === 200) {
        // 从所有景点中随机选择4个
        const allDestinations = response.data.data.content
        const shuffled = allDestinations.sort(() => 0.5 - Math.random())
        destinations.value = shuffled.slice(0, 4)
      }
    } catch (error) {
      console.error('获取景点列表失败:', error)
    }
  }

  onMounted(() => {
    fetchDestinations()
  })

  return {
    destinations
  }
} 